﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LDSP.BRL;
using LDSP.Helper;

namespace LDSP.UI.Admin
{
    public partial class LogTextPopup : LDSP.BRL.BaseValidUserPage
    {
        private string DocType { get; set; }
        private int ItemID { get; set; }
        public string Keywords { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    this.CheckQS();
                }
                if (this.RB())
                {
                    if (!IsPostBack)
                    {
                        InitialData();
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }

        protected void CheckQS()
        {
            try
            {
                DocType = this.Request.QueryString["type"];
            }
            catch
            {
                this.JSAlert("Doc Type is invalid.");
            }

            try
            {
                ItemID = this.GetInt(this.Request.QueryString["ID"]);
            }
            catch
            {
                this.JSAlert("Doc Type is invalid.");
            }

            try
            {
                Keywords = Server.UrlDecode(this.Request.QueryString["keywords"]);
            }
            catch
            {
                this.JSAlert("Keywords is invalid.");
            }

        }

        protected bool RB()
        {
            return true;
        }

        private void InitialData()
        {
            string content = string.Empty;
            switch (DocType)
            {
                case LongTextInstanceNames.ChemicalCatalog:
                    {
                        ChemicalCatalog ett = new ChemicalCatalog();
                        ett.GetProperties(ItemID);
                        content = ett.Summary;
                        break;
                    }
                case LongTextInstanceNames.News:
                    {
                        News news = new News();
                        news.GetProperties(ItemID);
                        content = news.Menu;
                        break;
                    }
                case LongTextInstanceNames.AccidentCase_Summary:
                    {
                        AccidentCase ac = new AccidentCase();
                        ac.GetProperties(ItemID);
                        content = ac.Summary;
                        break;
                    }
                case LongTextInstanceNames.AccidentCase_Result:
                    {
                        AccidentCase ac = new AccidentCase();
                        ac.GetProperties(ItemID);
                        content = ac.Result;
                        break;
                    }
                case LongTextInstanceNames.AccidentCase_Reference:
                    {
                        AccidentCase ac = new AccidentCase();
                        ac.GetProperties(ItemID);
                        content = ac.Reference;
                        break;
                    }
                case LongTextInstanceNames.Codification_KeyItems:
                    {
                        Codification c = new Codification();
                        c.GetProperties(ItemID);
                        content = c.KeyItems;
                        break;
                    }
                default: break;
            }

            this.lblContent.Text = this.Highlight(content, Keywords).Replace("\r\n", "<br/>");
        }
    }
}